<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>工控机基础管理</title>
<jsp:include page="../../views/layout/inc.jsp"></jsp:include>
<script type="text/javascript">
	$.canEdit = true;
	$.canDelete = true;
	
	var dataGrid;
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '/equipmentDevDnsController/dataGrid',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'id',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			singleSelect : true,
			nowrap : false,
			frozenColumns : [ [ {
				field : 'id',
				title : '编号',
				width : 150,
				hidden : true
			} ] ],
			columns : [ [ {
				field : 'residenceName',
				title : '所属小区',
				width : 70
			},{
				field : 'residenceId',
				title : '小区id',
				width : 80
			},{
				field : 'doorId',
				title : '门牌id',
				width : 60
			},{
				field : 'ddns',
				title : 'DDNS值',
				width : 60
			},{
				field : 'doorName',
				title : '门牌号',
				width : 60
			},{
				field : 'status',
				title : '状态',
				width : 60,
				formatter:function(val,rec){ 
					if(val == 1) {
						return '正常';
					}else if(val == 2) {
						return '删除';
					}
				}
			}, {
				field : 'gmtCreate',
				title : '创建时间',
				width : 100,
				formatter:function(val,rec){
					if(val!='' && val!=null){
						 var unixTimestamp = new Date(val);  
						 return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");
					}
				}
			}, {
				field : 'gmtModify',
				title : '更新时间',
				width : 100,
				formatter:function(val,rec){
					if(val!='' && val!=null){
						 var unixTimestamp = new Date(val);  
						 return unixTimestamp.format("yyyy-MM-dd hh:mm:ss"); 
					}
				}
			}, { field:'action',title:'操作',width:60,formatter : function(value, row, index) {
					var str = '';
					if ($.canEdit) {
						str += $.formatString('<img onclick="editDevice(\'{0}\');" src="{1}" title="修改"/>', row.id, '${path}/images/extjs_icons/pencil.png');
					}
					/* str += '&nbsp;';
					if ($.canDelete) {
						str += $.formatString('<img onclick="delDevice(\'{0}\');" src="{1}" title="删除"/>', row.id, '${path}/images/extjs_icons/cancel.png');
					} */
					return str;
				}}
			] ],
			toolbar : '#toolbar',
			onLoadSuccess : function() {
				$('#searchForm  table').show();
				parent.$.messager.progress('close');
				$(this).datagrid('tooltip');
			},
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll').datagrid('uncheckAll');
				$(this).datagrid('selectRow', rowIndex);
			}
		});
	});

	function searchFun() {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
	}
	
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
	}
	
	// 新增
	function addIpc() {
		parent.$.modalDialog({
			title : '新增DDNS',
			width : 500,
			height : 320,
			href : '/equipmentDevDnsController/addPage',
			buttons : [ {
				text : '确认新增',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}
	
	//修改
	function editDevice(id){
		parent.$.modalDialog({
			title : '修改',
			width : 500,
			height : 320,
			href : '/equipmentDevDnsController/editPage?id=' + id,
			buttons : [ {
				text : '确认修改',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}
	
	//删除
	function delDevice(id){
		parent.$.messager.confirm('询问', '是否确认删除所选择设备，删除后无法恢复!', function(b) {
		if (b) {
			parent.$.messager.progress({
				title : '提示',
				text : '数据处理中，请稍后....'
			});
			$.post('/equipmentDevIpcController/delete', {
					id : id
				}, function(result) {
					if (result.success) {
						parent.$.messager.alert('提示', result.msg, 'info');
						dataGrid.datagrid('reload');
					}else{
						parent.$.messager.alert('提示',result.msg,'info');
					}
					parent.$.messager.progress('close');
				}, 'JSON');
			}
		});
	}
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 60px; overflow: hidden;">
			<form id="searchForm">
				<table class="table table-hover table-condensed" style="display: none;">
					<tr>
						<th>ddns值</th>
						<td>
							<input id="ddns" name="ddns" placeholder="模糊查询" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
		<a onclick="addIpc();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">新增</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">提交查询</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="cleanFun();">重置查询</a>
	</div>
</body>
</html>